/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.constant;

import java.util.Arrays;

public final class Dict {
    private Dict() {
    }

    public static final String OI_MARK = "oi";
    public static final String COMMON_CONFIG_FILE = "oi.yaml";
    public static final String APPLICATION_CONFIG_FILE = "application.yml";
    public static final String APISERVER_CONFIG_FILE = "apiserver_application.yaml";
    public static final String MASTER_CONFIG_FILE = "master_application.yaml";
    public static final String WORKER_CONFIG_FILE = "worker_application.yaml";
    public static final String APISERVER_MARK = "apiserver";
    public static final String MASTER_MARK = "master";
    public static final String WORKER_MARK = "worker";
    public static final String CONSOLE_MARK = "console";
    public static final String FEDERATED_PROXY_MARK = "federatedproxy";
    public static final String DEFAULT_ENGINES_MARK = "default_engines";
    public static final String NODE_ID = "node_id";
    public static final String OPERATOR_DEFINE_FILE = "operator.yaml";

    // env vm options params
    public static final String OI_EXTERNAL_CONFIG = "oi.external.config";
    public static final String CLI_OI_APISERVER_HOST = "oi.apiserver.host";
    public static final String CLI_OI_APISERVER_HTTP_PORT = "oi.apiserver.http.port";
    public static final String CLI_OI_APISERVER_GRPC_PORT = "oi.apiserver.grpc.port";

    // config item
    public static final String VALUE_RETRY_NUMBER = "${retry.number:3}";
    public static final String VALUE_NODE_OFFLINE_CHECK = "${node.offline_check:3}";
    public static final String VALUE_CONTEXT_PATH = "${server.servlet.context-path}";
    public static final String VALUE_REST_READ_TIMEOUT = "${rest-template.read-timeout}";
    public static final String VALUE_REST_CONNECT_TIMEOUT = "${rest-template.connect-timeout}";
    public static final String VALUE_NODE_VERIFY_TIMER = "${scheduled.verify_timer}";
    public static final String VALUE_NODE_STATUS_TIMER = "${scheduled.status_timer}";
    public static final String VALUE_NODE_BREAK_TIMER = "${scheduled.break_timer}";
    public static final String WORKER_HOST = "${worker.host}";
    public static final String WORKER_HTTP_PORT = "${worker.http_port}";
    public static final String WORKER_GRPC_PORT = "${worker.grpc_port}";
    public static final String FEDERATEDPROXY_HOST = "${federatedproxy.host}";
    public static final String FEDERATEDPROXY_HTTP_PORT = "${federatedproxy.http_port}";
    public static final String FEDERATEDPROXY_GRPC_PORT = "${federatedproxy.grpc_port}";
    public static final String FEDERATEDPROXY_PROTOCOL = "${federatedproxy.protocol}";
    public static final String OPERATOR_RUNTIME_LOG_LEVEL = "${operator.log_level}";
    public static final String OPERATOR_RUNTIME_PROFILE_LOG_ENABLED = "${operator.profile_log_enabled}";
    public static final String OPERATOR_RUNTIME_LAUNCH_TIMEOUT = "${operator.launch_timeout}";
    public static final String OPERATOR_RUNTIME_HEARTBEAT_TIMEOUT = "${operator.heartbeat_timeout}";
    public static final String OPERATOR_RUNTIME_DEFAULT_COMPUTING_ENGINE = "${operator.computing}";
    public static final String OPERATOR_RUNTIME_DEFAULT_STORAGE_ENGINE = "${operator.storage}";
    public static final String OPERATOR_RUNTIME_DEFAULT_QUEUE_ENGINE = "${operator.queue}";
    public static final String KAFKA_SERVERS = "${kafka.servers}";
    public static final String NODE_HEARTBEAT_CHECK_TIME_SECOND = "${node.heartbeat_check_time:60}";
    public static final String SERVER_NAME = "service-name";

    public static final String PYTHONPATH = "PYTHONPATH";
    public static final String JAVA_HOME = "JAVA_HOME";
    public static final String SPARK_HOME = "SPARK_HOME";

    // state rules
    public static final String TASK_STATE_RULES = "task_state_rules.yaml";
    public static final String STATE_COLLECTION = "state_collection";
    public static final String JOB_STATE_TRANSITION_RULE = "job_state_transition_rule";
    public static final String TASK_STATE_TRANSITION_RULE = "task_state_transition_rule";
    public static final String NODE_STATE_TRANSITION_RULE = "node_state_transition_rule";
    public static final String INTERRUPT_JOB_STATES = "INTERRUPT_JOB_STATES";
    public static final String FINISHED_JOB_STATES = "FINISHED_JOB_STATES";
    public static final String INTERRUPT_TASK_STATES = "INTERRUPT_TASK_STATES";
    public static final String FINISHED_TASK_STATES = "FINISHED_TASK_STATES";
    public static final String CAN_DELETE_NODE_STATES = "CAN_DELETE_NODE_STATES";
    public static final String COOPERATION_NODE_STATES = "COOPERATION_NODE_STATES";

    // logs
    public static final String LOG_PATH_PROPERTY = "log_path";
    public static final String LOG_LEVEL_PROPERTY = "log_level";
    public static final String LOG_PATH_ROOT = "logs/";
    public static final String LOG_LEVEL_DEFAULT = "INFO";

    private static final String[] SERVICE_CLASS_NAMES = {
            "org.openislands.oi.bootstrap.Apiserver",
            "org.openislands.oi.bootstrap.Master",
            "org.openislands.oi.bootstrap.Worker",
            "org.openislands.oi.bootstrap.Console",
    };

    public static String[] getServiceClassNames() {
        return Arrays.copyOf(SERVICE_CLASS_NAMES, SERVICE_CLASS_NAMES.length);
    }

    public static <T> T aNull() {
        return null;
    }
}
